
package com.platform.modules.bk.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.platform.common.annotation.SysLog;
import com.platform.common.utils.RestResponse;
import com.platform.modules.bk.entity.BkCustomerEntity;
import com.platform.modules.bk.service.BkCustomerService;
import com.platform.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 客户号对应数据Controller
 *
 * @author 
 * @date 2022-04-20 15:28:42
 */
@RestController
@RequestMapping("bk/customer")
public class BkCustomerController extends AbstractController {
    @Autowired
    private BkCustomerService bkCustomerService;

    /**
     * 查看所有列表
     *
     * @param params 查询参数
     * @return RestResponse
     */
    @RequestMapping("/queryAll")
    @RequiresPermissions("bk:customer:list")
    public RestResponse queryAll(@RequestParam Map<String, Object> params) {
        List<BkCustomerEntity> list = bkCustomerService.queryAll(params);

        return RestResponse.success().put("list", list);
    }

    /**
     * 分页查询客户号对应数据
     *
     * @param params 查询参数
     * @return RestResponse
     */
    @GetMapping("/list")
    @RequiresPermissions("bk:customer:list")
    public RestResponse list(@RequestParam Map<String, Object> params) {
        Page page = bkCustomerService.queryPage(params);

        return RestResponse.success().put("page", page);
    }

    /**
     * 根据主键查询详情
     *
     * @param customerNo 主键
     * @return RestResponse
     */
    @RequestMapping("/info/{customerNo}")
    @RequiresPermissions("bk:customer:info")
    public RestResponse info(@PathVariable("customerNo") String customerNo) {
        BkCustomerEntity bkCustomer = bkCustomerService.getById(customerNo);

        return RestResponse.success().put("customer", bkCustomer);
    }

    /**
     * 新增客户号对应数据
     *
     * @param bkCustomer bkCustomer
     * @return RestResponse
     */
    @SysLog("新增客户号对应数据")
    @RequestMapping("/save")
    @RequiresPermissions("bk:customer:save")
    public RestResponse save(@RequestBody BkCustomerEntity bkCustomer) {

        bkCustomerService.add(bkCustomer);

        return RestResponse.success();
    }

    /**
     * 修改客户号对应数据
     *
     * @param bkCustomer bkCustomer
     * @return RestResponse
     */
    @SysLog("修改客户号对应数据")
    @RequestMapping("/update")
    @RequiresPermissions("bk:customer:update")
    public RestResponse update(@RequestBody BkCustomerEntity bkCustomer) {

        bkCustomerService.update(bkCustomer);

        return RestResponse.success();
    }

    /**
     * 根据主键删除客户号对应数据
     *
     * @param customerNos customerNos
     * @return RestResponse
     */
    @SysLog("删除客户号对应数据")
    @RequestMapping("/delete")
    @RequiresPermissions("bk:customer:delete")
    public RestResponse delete(@RequestBody String[] customerNos) {
        bkCustomerService.deleteBatch(customerNos);

        return RestResponse.success();
    }
}
